var _pInfo = {
	"userInfo": null,
	"param": getQueryParams(),
	"renderData": function() {
		AjaxRequest({
			url: _url + "/money/wallet/mywallet",
			type: "post",
			load: true,
			data: {
				"userid": _pInfo.userInfo["id"]
			},
			success: function(rs) {
				if(isReqSucceed(rs)) {
					var _str = _pInfo.param["type"] == 0 ? "云币" : "云积分";
					var _val = _pInfo.param["type"] == 0 ? rs.data.yunB : rs.data.yunScore;
					$("#tips").html("账户余额：" + _val + _str);
				}
			}
		});
	},
	"showPwdPopup": function() {
		var accountnumber = $("#accountnumber").val().trim();
		var money = $("#money").val().trim();
		var phoneReg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
		var moneyReg = /^\+?[1-9][0-9]*$/;
		if(isNull(accountnumber)) {
			$.toast("请输入收款方手机号码", "text");
			return;
		}
		if(!phoneReg.test(accountnumber)) {
			$.toast("请输入正确的手机号", "text");
			return;
		}
		if(isNull(money)) {
			$.toast("请输入转账金额", "text");
			return;
		}
		if(!moneyReg.test(money)) {
			$.toast("转账金额必须是正整数", "text");
			return;
		}
		$("#pwd-popup").popup();
	},
	"doValidatePwd": function() {
		var _safetyPasswd = $("#popup-ipt").val().trim();
		if(isNull(_safetyPasswd)) {
			$.toast("请输入资金密码", "text");
			return;
		}
		if(_safetyPasswd.length < 6) {
			$.toast("资金密码必须为6位数", "text");
			return;
		}
		if(isNaN(_safetyPasswd)) {
			$.toast("资金密码必须是纯数字", "text");
			return;
		}
		var _data = {
			"userid": _pInfo.userInfo["id"],
			"safetyPasswd": _safetyPasswd
		}
		AjaxRequest({
			url: _url + "/money/wallet/paypwdproving",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					_pInfo.doSubmitData();
				}
			}
		});
	},
	"doSubmitData": function() {
		var accountnumber = $("#accountnumber").val().trim();
		var money = $("#money").val().trim();
		var _data = {
			"userid": _pInfo.userInfo["id"],
			"accountnumber": accountnumber,
			"money": money,
			"moneytype": _pInfo.param["type"]
		}
		AjaxRequest({
			url: _url + "/money/wallet/outmoney",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					$.alert("转账成功", function() {
						window.location.href = "wallet-detail.html?type=" + _pInfo.param["type"];
					});
				}
			}
		});
	},
	"loadEvents": function() {
		_pInfo.userInfo = _user.getUserInfo();
	},
	"load": function() {
		this.loadEvents();
		this.renderData();
	}
}
exposeGlobalMethods({
	"showPwdPopup": function() {
		_pInfo.showPwdPopup();
	},
	"doSubmitData": function() {
		_pInfo.doSubmitData();
	},
	"doValidatePwd": function() {
		_pInfo.doValidatePwd();
	}
});
$(function() {
	_pInfo.load();
});

function getAccountByQrcode(str) {
	$("#accountnumber").val(str);
}